﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IPC.Communication.Core;
using IPC.Communication.ModBus;

namespace IPC.Communication.Profinet.Delta
{
    public class DeltaDvpSerial : ModbusRtu
{
	public DeltaDvpSerial()
	{
		base.ByteTransform.DataFormat = DataFormat.CDAB;
	}

	public DeltaDvpSerial(byte station = 1)
		: base(station)
	{
		base.ByteTransform.DataFormat = DataFormat.CDAB;
	}

	public override OperateResult<string> TranslateToModbusAddress(string address, byte modbusCode)
	{
		return DeltaHelper.PraseDeltaDvpAddress(address, modbusCode);
	}

	public override OperateResult<bool[]> ReadBool(string address, ushort length)
	{
		return DeltaHelper.ReadBool(base.ReadBool, address, length);
	}

	public override OperateResult Write(string address, bool[] values)
	{
		return DeltaHelper.Write(base.Write, address, values);
	}

	public override OperateResult<byte[]> Read(string address, ushort length)
	{
		return DeltaHelper.Read(base.Read, address, length);
	}

	public override OperateResult Write(string address, byte[] value)
	{
		return DeltaHelper.Write(base.Write, address, value);
	}

	public override string ToString()
	{
        return String.Format("DeltaDvpSerial[{0}:{1}]", base.PortName, base.BaudRate);
	}
}
}
